package com.itpeng.mobile;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itpeng.Utils.QiNiuUtils;
import com.itpeng.constant.MessageConstant;
import com.itpeng.entity.Result;
import com.itpeng.pojo.Setmeal;
import com.itpeng.service.SetmealMobileService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Aythor:彭彦钦
 * @Data: 2020/9/24  15:01
 */
@RestController
@RequestMapping("/setMeal")
public class SetmealMobileController {

    @Reference
    private SetmealMobileService setmealMobileService;

    /**
     * 查询所有套餐
     * @return
     */
    @GetMapping("/getSetmeal")
    public Result getSetmeal(){
        List<Setmeal> setmealList = setmealMobileService.getSetmeal();
        for (Setmeal setmeal : setmealList) {
            setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        }
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
    }

    /**
     * 查询套餐详情
     * @param id
     * @return
     */
    @GetMapping("/findDetailById")
    public Result findDetailById(Integer id){
        Setmeal setmeal = setmealMobileService.findDetailById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }

    @GetMapping("/findById")
    public Result findById(Integer id){
        Setmeal setmeal = setmealMobileService.findById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }


}
